<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title></title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../static/shopPrivate/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="../static/shopPrivate/css/thesame.css" media="all">
	<link rel="stylesheet" href="../static/shopPrivate/css/page.css" media="all">
	<link rel="stylesheet" href="../static/shopPrivate/shopManage/css/rightCon.css" media="all">
	<link rel="stylesheet" href="../static/shopPrivate/shopManage/css/popCss.css" media="all">
	<style type="text/css">
		.layui-btn{ height: 32px; line-height: 32px; }
	</style>
</head>

<body class="layui-layout-body">
	<div class="layui-body ">
		<!-- 内容主体区域 -->
		<div class="scroll-box">
			<div class="scroll-box-con">
				<div class="crumbs-nav f14px pb16px">
					<span class="current">批量导入</span>
				</div>
				<div class="pad16px border-radius4 bgWhite">
					<div class="new-data-btn mb16px lh30px overflow">
						<p class="left" onclick="layerOpenOne()">
							<span class="white border-radius4 bgBlue inline-block cursor">
							<img src="../static/shopPrivate/shopManage/img/button_drsp.png" style="vertical-align: -3px;">导入商铺</span>
						</p>
						<p class="right"><span class="block">共<em class="red" id="totalNum"></em>条数据</span></p>
					</div>
					<div class="table-center">
						<table class="layui-hide" id="test" lay-filter="test"></table>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div id="pop-con" style="display: none;">
		<div class="pop-up">
			<p class="pop-title-top"><span>导入商铺信息</span><span class="pop-close right"><img src="../static/shopPrivate/shopManage/img/icon_close.png"></span></p>
			<div class="pad24px">
				<div class="add-mess">
					<div class="add-mess-child">
						<div>
							<label>导入文件：</label>
						</div>
						<p>

							<button type="button" class="white border-radius4 bgBlue inline-block cursor textCenter layui-btn layui-btn-normal" style="width: 100px;" id="choseFileButton">选&nbsp;择</button>
							<!-- <span class="white border-radius4 bgBlue inline-block cursor textCenter" style="width: 100px;">选&nbsp;择</span> -->
						</p>
					</div>
					<div class="add-mess-child layui-form">
						<div>
							<label>导入规则：</label>
						</div>
						<p>
							<span class="block"><input type="radio" name="addOrCover" checked="checked" value="2" lay-skin="primary" title="更新已有数据"></span>
							<span class="block"><input type="radio" name="addOrCover" value="1" lay-skin="primary" title="不更新"></span>
						</p>
					</div>
				</div>
			</div>
			<div class="btn-con overflow textCenter lh40px pt16px pb16px border-top1px">
				<span class="blue left" onclick="getReportTemplate()">下载模板</span>
				<span class="btn-submit right" style="margin-right: 32px;" id="confirmButton">开始导入</span>
			</div>
		</div>
	</div>
<script src="../static/shopPrivate/js/jquery-3.1.1.min.js"></script>
<script src="../static/shopPrivate/layui/layui.js" charset="utf-8"></script>
<script>


	$(function(){


		//导入文件
		layui.use('upload', function(){
			var upload = layui.upload;
			//选完文件后不自动上传
		  	upload.render({
		    	elem: '#choseFileButton'
		    	,url: '../report/importShopReport' //改成您自己的上传接口
		    	,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
				    layer.load(); //上传loading
				}
		    	,auto: false
		    	,accept: 'file'
		    	,bindAction: '#confirmButton'
		    	,exts:'xls|xlsx'
		    	,data:{
		    		//增加或者覆盖 1-增加 2-覆盖
		    		addOrCover:function(){
		    			var addOrCover =$("input:radio[name='addOrCover']:checked").val();//认知情况
		    			 console.log("addOrCover="+addOrCover);
		    			return addOrCover;
		    		}
		    		// ,
		    		// orgId:function(){
		    		// 	return registerAreaOfResidenceValue;
		    		// }
		    	}
		    	,done: function(res){
		    		// console.log(res);
		    		if (res.code==200) {
		    			layer.closeAll();
		    			layer.msg('上传成功,'+res.msg, {icon: 1},function(){
		    				query();
		    			});

		    		}else{
		    			layer.closeAll();
		    			layer.msg(res.msg, {icon: 2});
		    		}
		    	}
		    	,error:function(res){
		    		layer.closeAll('loading');
		    	}
		  	});
		})


		//查询
		query();
	})




	function query(){
		//左侧菜单栏
		layui.use(['table','layer'], function() {
			var table = layui.table;
			
			//第一个实例
			table.render({
				elem: '#test'//,url: '/demo/table/user/'
				,url:"../report/getReportRecordList"
				//,where: getformDate(liveCondition,overAllOrgId)
				,request: {
					 pageName: 'currentPage' //页码的参数名称，默认：page
					 ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
				}
				//,count: 10  //数据总数，从服务端得到
				//,data: listData
				,page: true //开启分页
				,limit:10 //每页显示的条数
				//,limits:[3,4,5]
				,groups: 9 //连续页码个数
				,parseData:function(res){
					return{
						"code":res.code,
						"data":res.data.data,
						"count":res.data.totalCount,
						"limit":res.data.pageSize,
					};
				}
				,cols: [
					[ //表头
						{
							field: 'id',
							title: '行号',
							fixed: 'left',
							type: 'numbers',
							width:100
						}, {
							field: 'createTime',
							title: '导入时间',
							// width:200
						}, {
							field: 'sign',
							title: '导入文件',
							templet: function(res){
								return '<div class="table-list-btn "><span class="blue cursor" onclick="getOriginalExcel(\''+res.id+'\')">'+res.reportName+'</span></div>';
							}
						}, {
							field: 'sysUserName',
							title: '操作员',
							width: 100,
						}, {
							field: 'operation',
							title: '导入结果',
							templet:function(res){

								if (res.failCount ==0) {
									return '<div><span>成功导入<em class="blue">'+res.successCount+' </em>条数据，</span><span>失败<em class="red">'+res.failCount+' </em>笔'
								}else{
									return '<div><span>成功导入<em class="blue">'+res.successCount+' </em>条数据，</span><span>失败<em class="red">'+res.failCount+' </em>笔'
								}
							}
						},{
							field: 'operation',
							title: '操作',
							// width: 300,
							fixed: 'right',
							templet: function(res){
								if (res.failCount ==0) {
									 return '';
								}else{
									return '<div class="table-list-btn"><span class="blue cursor" onclick="getErrorLogExcel(\''+res.id+'\')" >查看错误日志</span></div>';
								}
							}
						}
					]
				]
				,done:function(res, curr, count){
				    $("#totalNum").text(count);
				}
			});
		});


	}



	//下载模板
	function getReportTemplate(){
		window.location.href="../report/getShopReportTemplate";
	}

	//获取原始的excel
	function getOriginalExcel(reportId){
		window.location.href="../report/getOriginalExcel?reportId="+reportId;
	}

	//错误excel
	function getErrorLogExcel(reportId){
		window.location.href="../report/getErrorLogExcel?reportId="+reportId;
	}



	function layerOpenOne(){
		layer.open({
			type: 1  
			,title: false
			,closeBtn: false
			//新建组织
			,area: ['380px','']
			,shade: 0.2
			,id: 'payCons' 
			,btnAlign: 'c'
			,moveType: 1 
			,shadeClose: true
			,content: $("div#pop-con"),
			success:function(){
				//关闭弹层
				$(".pop-close").click(function(){
					layer.closeAll();
				});
			},
			
		});
	}






</script>
</body>

</html>
